
import 'dart:async';
import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:net_store/DataSource/DataStore.dart';
import 'package:net_store/Pages/MainPage.dart';
import 'package:net_store/main.dart';

class WelcomePage extends StatelessWidget {
  var running = false;

  void runTimer(BuildContext context){
    loadData();
    Timer(Duration(seconds: 3), (){
      Navigator.of(context).pushReplacement(MaterialPageRoute(builder: (context) => MainPage()));
    });
  }

  void loadData() async {
    DataStore.products = await dataSource.getAllProducts();
    DataStore.recommandations = await dataSource.getAllRecommandations();
    DataStore.hotStories = await dataSource.getAllHotStories();
    DataStore.stories = await dataSource.getAllStories();
  }

  @override
  Widget build(BuildContext context) {
    if (!running){
      runTimer(context);
      running = true;
    }
    return Scaffold(
      body: Container(
        width: double.infinity,
        height: double.infinity,
        child: Image.asset("assets/images/welcome.jpg", fit: BoxFit.fill,),
      )
    );
  }
}

